package com.xs.batch.controller;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/batch")
public class OrderBatchController {

    @Autowired
    private Job closeOrderJob;

    @Autowired
    private JobLauncher jobLauncher;

    @PostMapping("/close-orders")
    public String closeOrders() throws Exception {
        jobLauncher.run(
            closeOrderJob, 
            new JobParametersBuilder()
                .addLong("timestamp", System.currentTimeMillis()) // 保证每次参数唯一
                .toJobParameters()
        );
        return "关单任务已触发";
    }
}